<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="Bookmark" href="/favicon.ico">
    <link rel="Shortcut Icon" href="/favicon.ico"/>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="lib/html5shiv.js"></script>
    <script type="text/javascript" src="lib/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>异常订单列表</title>
</head>
<style>
    .table > tbody > tr > td {
        text-align: center;
    }
</style>
<body>

<div>
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 订单管理 <span
            class="c-gray en">&gt;</span> 异常订单列表 <a class="btn btn-success radius r"
                                                  style="line-height:1.6em;margin-top:3px"
                                                  href="javascript:location.replace(location.href);" title="刷新"><i
            class="Hui-iconfont">&#xe68f;</i></a></nav>
    <form class="page-container">
<%--        <div class="cl pd-5 bg-1 bk-gray mt-20">--%>
<%--            <span class="l">--%>
<%--                <a class="btn btn-primary radius" onclick="downloadExcel()" href="javascript:;">导出excel</a>--%>
<%--            </span>--%>
<%--        </div>--%>
<%--        <div class="panel panel-default  mt-20">--%>
<%--            <div class="panel-header">时间筛选</div>--%>
<%--            <div class="panel-body">--%>
<%--                <div class="skin-minimal" id="time-selector">--%>
<%--                    <div class="check-box">--%>
<%--                        <input type="radio" name="time" value="0">--%>
<%--                        <label>所有</label>--%>
<%--                    </div>--%>
<%--                    <div class="check-box">--%>
<%--                        <input type="radio" name="time" value="1" checked>--%>
<%--                        <label>当天</label>--%>
<%--                    </div>--%>
<%--                </div>--%>
<%--            </div>--%>
<%--        </div>--%>
        <div class="mt-20">
            <div class="mt-20" style="margin-bottom: 70px">
                <table class="table table-border table-bordered table-bg table-hover table-sort" width="100%">
                    <thead>
                    <tr class="text-c">
                        <th width="25"><input type="checkbox" name="" value=""></th>
                        <th width="80">订单号</th>
                        <th width="80">患者姓名</th>
                        <th width="80">联系电话</th>
                        <th width="100">物品清单</th>
                        <th width="60">下单时间</th>
<%--                        <th width="50">确认时间</th>--%>
<%--                        <th width="50">配药时间</th>--%>
                        <th width="50">配送时间</th>
                        <th width="100">配送地址</th>
<%--                        <th width="100">医保</th>--%>
<%--                        <th width="100">医保类型</th>--%>
                        <th width="80">派送人</th>
<%--                        <th width="40">配送费用</th>--%>
                        <th width="80">下单人</th>
                        <th width="80">取消时间</th>
                        <th width="80">取消原因</th>
<%--                        <th width="40">附件</th>--%>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
    </form>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script>

<script type="text/javascript" src="lib/datatables/dataTables.colReorder.min.js"></script>
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript" src="lib/common.js"></script>
<script type="text/javascript">

    var start = getTodayStart()
    var end = getTodayEnd()

    for (var i = 1;i<5;i++){
        var t = Date.parse(getTodayStart().replace(/-/g, "/"))
        t = t + i*24*60*60*1000
        $('#time-selector').append("<div class=\"check-box\"><input type=\"radio\" name=\"time\" value="+(parseInt(i)+1)+" ><label>"+dateymd(t)+"</label></div>")
    }



    // $('input[name=state],input[name=time]').change(function (e) {
    //
    //     radioValue = $('input[name=time]:checked').val()
    //     switch (radioValue) {
    //         case '1':
    //             start = getTodayStart()
    //             end = getTodayEnd()
    //             break
    //         case '0':
    //             start = ""
    //             end = ""
    //             break;
    //         default :
    //             console.log(radioValue)
    //             var t = Date.parse(getTodayStart().replace(/-/g, "/"))
    //             t = t + (radioValue-1)*24*60*60*1000
    //             start = dateAll(t)
    //             var e = Date.parse(getTodayEnd().replace(/-/g, "/"))
    //             e = e + (radioValue-1)*24*60*60*1000
    //             end = dateAll(e)
    //             break;
    //     }
    //     console.log(start, end)
    //
    //     table.destroy()
    //     table = $('.table').DataTable({
    //         serverSide: true,//开启服务器模式
    //         "processing": true,//加载显示提示
    //         "ajax": {
    //             url: "./order/cancel/list",
    //             type: 'GET',
    //             data: {
    //                 "searchKey": "",
    //                 "minDate": start,
    //                 "maxDate":end,
    //             }
    //         },
    //         "columns": [
    //             {
    //                 "data": null,
    //                 render: function (data, type, row, meta) {
    //                     return "<input name=\"checkbox\" value=\"" + row.orderId + "\" type=\"checkbox\" value=\"\">";
    //                 }
    //             },
    //             {"data": "orderId"},
    //
    //             {
    //                 "data": "receiverName"
    //             },
    //             {
    //                 "data": "receiverPhone"
    //             },
    //             {
    //                 "data": "medicineList",
    //                 render: function (data, type, row, meta) {
    //                     var s = ""
    //                     for (var i = 0;i<data.length;i++){
    //
    //                         var a ="<span><p>"+data[i].medicineName+data[i].standard +"   数量: "+data[i].num+"</p></span>"
    //                         s += a;
    //                     }
    //                     return s
    //                 }
    //             },
    //             {
    //                 "data": "createTime",
    //                 render: function (data, type, row, meta) {
    //                     return date(data);
    //                 }
    //             },
    //             {
    //                 "data": "reserveTime",
    //                 render: function (data, type, row, meta) {
    //                     return date(data);
    //                 }
    //             },
    //             {
    //                 "data": "receiverAddress"
    //             },
    //             // {
    //             //     "data": "insurance"
    //             // },
    //             // {
    //             //     "data": "insuranceType"
    //             // },
    //
    //             {
    //                 "data": "deliveryName"
    //             },
    //             // {
    //             //     "data": "cost"
    //             // },
    //             {
    //                 "data": "memberName"
    //             },
    //             {
    //                 "data": "cancelTime",
    //                 render: function (data, type, row, meta) {
    //                     return date(data);
    //                 }
    //             },
    //             {
    //                 "data": "cancelContent"
    //             },
    //             // {
    //             //     "data": null,
    //             //     render:function (data,type,row,meta){
    //             //         return '<a href=\"javascript:;\" onClick=\"openFile(\''+row.orderId+'\')\">附件列表</a>'
    //             //     }
    //             // },
    //         ],
    //         "aaSorting": [[1, "desc"]],//默认第几个排序
    //         "bStateSave": false,//状态保存
    //         "aoColumnDefs": [
    //             {"orderable": false, "aTargets": [0]}// 制定列不参与排序
    //         ],
    //         language: {
    //             url: './lib/datatables/Chinese.json'
    //         },
    //         colReorder: true
    //     });
    // })
    /*datatables配置*/
      var table =  $('.table').DataTable({
            serverSide: true,//开启服务器模式
            "processing": true,//加载显示提示
            "ajax": {
                url: "./order/cancel/list",
                type: 'GET',
                data: {
                    "searchKey": "",
                    // "minDate": start,
                    // "maxDate": end,
                }
            },
            "columns": [
                {
                    "data": null,
                    render: function (data, type, row, meta) {
                        return "<input name=\"checkbox\" value=\"" + row.orderId + "\" type=\"checkbox\" value=\"\">";
                    }
                },
                {"data": "orderId"},

                {
                    "data": "receiverName"
                },
                {
                    "data": "receiverPhone"
                },
                {
                    "data": "medicineList",
                    render: function (data, type, row, meta) {
                        var s = ""
                        for (var i = 0;i<data.length;i++){

                            var a ="<span><p>"+data[i].medicineName+data[i].standard +"   数量: "+data[i].num+"</p></span>"
                            s += a;
                        }
                        return s
                    }
                },
                {
                    "data": "createTime",
                    render: function (data, type, row, meta) {
                        return date(data);
                    }
                },
                {
                    "data": "reserveTime",
                    render: function (data, type, row, meta) {
                        return date(data);
                    }
                },
                {
                    "data": "receiverAddress"
                },
                // {
                //     "data": "insurance"
                // },
                // {
                //     "data": "insuranceType"
                // },
                {
                    "data": "deliveryName"
                },
                // {
                //     "data": "cost"
                // },
                {
                    "data": "memberName"
                },
                {
                    "data": "cancelTime",
                    render: function (data, type, row, meta) {
                        return date(data);
                    }
                },
                {
                    "data": "cancelContent"
                },
                //        {
                //     "data": null,
                //     render:function (data,type,row,meta){
                //         return '<a href=\"javascript:;\" onClick=\"openFile(\''+row.orderId+'\')\">附件列表</a>'
                //     }
                // },
            ],
            "aaSorting": [[1, "desc"]],//默认第几个排序
            "bStateSave": false,//状态保存
            "aoColumnDefs": [
                {"orderable": false, "aTargets": [0]}// 制定列不参与排序
            ],
            language: {
                url: './lib/datatables/Chinese.json'
            },
            colReorder: true
        });

    function msgSuccess(content) {
        layer.msg(content, {icon: 1, time: 3000});
    }
    function openFile(id){
        $.ajax({
            url:"./order/finish/id",
            methods:"get",
            data:{
                orderId:id
            },
            success(res){
                if (res.success){
                    var result = res.result
                    if (!result.radioPath && !result.chufangImg && !result.fapiaoImg){
                        layer.open({
                            type: 0,
                            content: '无任何附件信息' //这里content是一个普通的String
                        });
                    }else{
                        var html = ""
                        if (result.chufangImg){
                            html +="<div><div>处方照片</div><img width='500px' src="+result.chufangImg+"></div>"
                        }
                        if (result.fapiaoImg){
                            html +="<div><div>其他照片</div><img width='500px' src="+result.fapiaoImg+"></div>"
                        }
                        if (result.radioPath){
                            html +="<div><div>录音</div><audio controls src="+result.radioPath+"></div>"
                        }
                        layer.open({
                            type: 1,
                            content:html,
                            area:['600px','400px']
                        });
                    }

                }else{
                    layer.open({
                        type: 0,
                        content: '获取附件失败' //这里content是一个普通的String
                    });
                }
            }
        })
    }
    function downloadExcel() {
        var html = '  <div class="radio-box">\n' +
            '    <input type="radio" id="radio-1" value="1" name="demo-radio1">\n' +
            '    <label for="radio-1">全部</label>\n' +
            '  </div>  <div class="radio-box">\n' +
            '    <input type="radio" id="radio-2" value="2" name="demo-radio1" checked>\n' +
            '    <label for="radio-2">当天</label>\n' +
            '  </div>  <div class="radio-box">\n' +
            '    <input type="radio" id="radio-3" value="3" name="demo-radio1" checked>\n' +
            '    <label for="radio-3">自定义时间</label>\n' +
            '  </div>'
        html += `<input type="text" onfocus="WdatePicker({ maxDate:'#F{$dp.$D(\\'maxDate\\')||\\'%y-%M-%d\\'}' })" id="minDate" name="minDate" class="input-text Wdate" style="width:120px;"> -<input type="text" onfocus="WdatePicker({ minDate:'#F{$dp.$D(\\'minDate\\')}',maxDate:'%y-%M-%d' })" id="maxDate" name="maxDate" class="input-text Wdate" style="width:120px;">`
        layer.confirm(html, {area:[400,200],title:"选择时间"}, function (index) {
          var value = $('input[name=demo-radio1]:checked').val()
            var minDate = ""
            var maxDate = ""
          if(value == "2"){
                minDate = getTodayStart()
              maxDate = getTodayEnd()
            }else  if(value =="3"){
              if ($("#minDate").val() ==""){
                  alert("请选择开始时间")
                  return
              }
              if ( $("#maxDate").val()==""){
                  alert("请选择结束时间")
                  return;
              }
              minDate = $("#minDate").val()+" 00:00:00"
              maxDate = $("#maxDate").val() +" 23:59:59"
            }
            var index = layer.load(3);

            $.ajax({
                type: 'get',
                url: './order/download',
                headers:{
                    'Accept':'application/json, text/plain, */*',
                    'Connection':'keep-alive' ,
                    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
                    'X-Requested-With': 'XMLHttpRequest'
                },
                data:{
                    minDate:minDate,
                    maxDate:maxDate
                },
                xhrFields: { responseType: "arraybuffer" },
                success:function(data){
                    layer.close(index);
                    var url = window.URL.createObjectURL(new Blob([data]))
                    var a = document.createElement('a');
                    a.style.display = 'none'
                    a.href = url
                    a.setAttribute('download', '异常订单.xlsx')
                    a.click()
                },
                error:function(e){
                    layer.close(index);
                    console.log(XMLHttpRequest)
                    layer.alert('下载失败!',{title: '错误信息',icon: 2});
                }
            });
        })
        }
</script>
</body>
</html>